package com.eastfair.notice.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.eastfair.boot.service.SuperServiceImpl;
import com.eastfair.core.base.R;
import com.eastfair.notice.dao.MsgLogMapper;
import com.eastfair.notice.entity.MsgLog;
import com.eastfair.notice.service.MsgLogService;
import com.eastfair.projectcore.api.ProjectCoreServiceFeign;
import com.eastfair.core.snowflake.DefaultUidGenerator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 业务实现类
 * 消息发送记录
 * </p>
 *
 * @author liuxiaobai
 * @date 2021-08-04
 */
@Slf4j
@Service
public class MsgLogServiceImpl extends SuperServiceImpl<MsgLogMapper, MsgLog> implements MsgLogService {
    @Autowired
    ProjectCoreServiceFeign projectCoreServiceFeign;

    /**************sharding 分库分表操作 *****************/
    @Override
    public boolean updateByIdOfShard(MsgLog entity) {
        UpdateWrapper<MsgLog> updateWrapper = new UpdateWrapper<>();
        //可将指定字段更新为null
        updateWrapper.lambda().eq(MsgLog::getProjectId, entity.getProjectId()).eq(MsgLog::getId, entity.getId());
        entity.setProjectId(null);
        return SqlHelper.retBool(this.getBaseMapper().update(entity, updateWrapper));
    }

    @Override
    protected R<Boolean> handlerSave(MsgLog model) {
        //雪花ID
        model.setId(DefaultUidGenerator.getUidOfProjectId(model.getProjectId()));
        return R.successDef();
    }

}
